package model.bo;

import model.bean.Vaga;
import model.persistencia.dao.HibernateUtil;
import model.persistencia.dao.VagaDAO;

public class VagaBO{
	
	private VagaDAO vagaDAO = new VagaDAO(Vaga.class);
	
	public Vaga incluir(Vaga vaga) throws Exception{ 
		HibernateUtil.getInstance().startTransaction();
		try {
			vaga = vagaDAO.save(vaga);
			HibernateUtil.getInstance().commitTransaction();
		} catch (Exception e) {
			HibernateUtil.getInstance().rollbackTransaction();
		}
		return vaga;
	}
	
	public void salvar(Vaga vaga) throws Exception{	 
		HibernateUtil.getInstance().startTransaction();
		try {
			vagaDAO.save(vaga);
			HibernateUtil.getInstance().commitTransaction();
		} catch (Exception e) {
			HibernateUtil.getInstance().rollbackTransaction();
		}
	}
	
	public void excluir(Vaga vaga) throws Exception{
		HibernateUtil.getInstance().startTransaction();
		try {
			vagaDAO.delete(vaga);
			HibernateUtil.getInstance().commitTransaction();
		} catch (Exception e) {
			HibernateUtil.getInstance().rollbackTransaction();
		}
	}
	
	public Vaga consultar(Vaga vaga) throws Exception{
		try {
			vaga = vagaDAO.load(vaga.getId());
		} catch (Exception e) {
			HibernateUtil.getInstance().rollbackTransaction();
		}
		return vaga;
	}

}
